package cn.proxy.proxy;

import cn.proxy.domain.Student;
import cn.proxy.service.IStudentService;
import cn.proxy.service.impl.StudentServiceImpl;
import cn.proxy.transaction.DaoTransaction;

/**
 * @author 董代恒
 * @version 1.0
 */
public class ProxyStudent implements IStudentService {
    //目标对象
    private StudentServiceImpl studentService;

    //需要做的增强对象
    private DaoTransaction transaction;

    //通过构造器获取目标类和增强类对象
    public ProxyStudent(StudentServiceImpl studentService,DaoTransaction  transaction) {
        this.studentService = studentService;
        this.transaction = transaction;
    }
    @Override
    public void save(Student student) {
        //开启事务操作
        transaction.before();
        //目标类操作
        studentService.save(student);
        //关闭事务操作
        transaction.after();
    }

    @Override
    public Student query(Long id) {
        System.out.println("查询操作");
        return studentService.query(id);
    }
}
